package com.example.musicserver.mapper;

import com.example.musicserver.model.Music;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MusicMapper {
    /**
     * 上传前，查询歌曲是否存在
     * @param title
     * @param singer
     * @return
     */
    @Select("select * from music where title=#{title} and singer=#{singer}")
    Music selectMusicByTitleAndSinger(String title, String singer);

    /**
     * 往数据库里添加音乐
     * @param title
     * @param singer
     * @param time
     * @param url
     * @param userid
     * @return
     */
    @Insert("insert into music(title,singer,time,url,userid) values(#{title},#{singer},#{time},#{url},#{userid})")
    int insertMusic(String title, String singer,String time,String url,Integer userid);

    /**
     * 查询所有音乐
     * @return
     */
    @Select("select * from music")
    List<Music> showMusic();

    /**
     * 支持模糊查询音乐
     * @param musicName
     * @return
     */
    @Select("select * from music where title like concat('%',#{musicname},'%')")
    List<Music> showMusicByName(String musicName);

    @Select("select * from music where id=#{musicId}")
    Music selectMusicById(Integer musicId);

    /**
     * 通过音乐的id 来删除
     * @param musicId
     * @return
     */
    @Delete("delete from music where id=#{musicId}")
    int deleteMusicByMusicId(Integer musicId);
}
